package com.zret.oasys.operation.position;

import java.io.IOException;

import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zret.oasys.entity.Emp;
import com.zret.oasys.entity.Position;
public class GetPosition implements PositionServletOperation {

	@Override
	public void doOperation(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
         //	设置编码
		response.setContentType("application/json;Charset=utf-8");
		//获取信息
		String position =request.getParameter("position");
		if("".equals(position)) {
			//调用服务层模糊查询方法
			List<Position> list =pss.getByLikeId(position);
			//输入流
			PrintWriter out =response.getWriter();
			//创建JSON对象
			Gson gson=new Gson();
			String jsonString=gson.toJson(list);
			//测试
			System.out.println(jsonString);
			//输出到jsp
			out.print(jsonString);
			//关闭流
			out.close();
		}else {
		String positionString=	request.getParameter("position");
		  List<Position>list=pss.getByLikeId(positionString);
			// 3.创建输出流
			PrintWriter out = response.getWriter();
			// 4.创建Gson对象
		   Gson gson=new Gson();
		 
			// 5.将查询到的员工list转为字符串
			String jsonString = gson.toJson(list);
			// 6.控制台测试打印
			System.out.println(jsonString);
			// 7.传输给jsp页面
			out.print(jsonString);
			// 8.关闭out
			out.close();
		}
		

	}

}
